package com.hotel.project.system.roomorders.controller;

import com.hotel.common.utils.poi.ExcelUtil;
import com.hotel.framework.aspectj.lang.annotation.Log;
import com.hotel.framework.aspectj.lang.enums.BusinessType;
import com.hotel.framework.web.controller.BaseController;
import com.hotel.framework.web.domain.AjaxResult;
import com.hotel.framework.web.page.TableDataInfo;
import com.hotel.project.system.roomorders.domain.RoomOrders;
import com.hotel.project.system.roomorders.service.IRoomOrdersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客房订单 信息操作处理
 *
 * @author pluto
 * @date 2019-04-06
 */
@Controller
@RequestMapping("/system/roomOrders")
public class RoomOrdersController extends BaseController {
    private String prefix = "system/orders";

    @Autowired
    private IRoomOrdersService roomOrdersService;

    @RequiresPermissions("system:roomOrders:view")
    @GetMapping()
    public String roomOrders() {
        return prefix + "/roomOrders";
    }

    /**
     * 查询客房订单列表
     */
    @RequiresPermissions("system:roomOrders:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RoomOrders roomOrders) {
        startPage();
        List<RoomOrders> list = roomOrdersService.selectRoomOrdersList(roomOrders);
        return getDataTable(list);
    }


    /**
     * 导出客房订单列表
     */
    @RequiresPermissions("system:roomOrders:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RoomOrders roomOrders) {
        List<RoomOrders> list = roomOrdersService.selectRoomOrdersList(roomOrders);
        ExcelUtil<RoomOrders> util = new ExcelUtil<RoomOrders>(RoomOrders.class);
        return util.exportExcel(list, "roomOrders");
    }

    /**
     * 新增客房订单
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存客房订单
     */
    @RequiresPermissions("system:roomOrders:add")
    @Log(title = "客房订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RoomOrders roomOrders) {
        return toAjax(roomOrdersService.insertRoomOrders(roomOrders));
    }

    /**
     * 修改客房订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        RoomOrders roomOrders = roomOrdersService.selectRoomOrdersById(id);
        mmap.put("roomOrders", roomOrders);
        return prefix + "/edit";
    }

    /**
     * 修改保存客房订单
     */
    @RequiresPermissions("system:roomOrders:edit")
    @Log(title = "客房订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RoomOrders roomOrders) {
        return toAjax(roomOrdersService.updateRoomOrders(roomOrders));
    }

    /**
     * 删除客房订单
     */
    @RequiresPermissions("system:roomOrders:remove")
    @Log(title = "客房订单", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(roomOrdersService.deleteRoomOrdersByIds(ids));
    }

}
